#!/bin/sh

## Copyright 2019-2020 Vagrant Cascadian <vagrant@debian.org>

## This program comes with ABSOLUTELY NO WARRANTY; for details see
## COPYING.  This is free software, and you are welcome to
## redistribute it under the terms of the GNU GPL, version 2 or any
## later version; see COPYING for details.

# sync .dtb files into /boot to simplify installations on systems with
# a split /boot partition.  To use, install this file into
# /etc/kernel/postinst.d/zz-sync-dtb and mark it as executable.

set -e

version="$1"

command -v rsync >/dev/null 2>&1 || exit 0

# passing the kernel version is required
if [ -z "${version}" ]; then
	echo >&2 "W: sync-dtb: ${DPKG_MAINTSCRIPT_PACKAGE:-kernel package} did not pass a version number"
	exit 2
fi

dtbdir="/usr/lib/linux-image-${version}"



if [ -d "${dtbdir}" ]; then
	echo >&2 "W: sync-dtb: syncing ${dtbdir}"
	mkdir -p "/boot/${dtbdir}"
	rsync -a "${dtbdir}/." "/boot/${dtbdir}/."
else
	echo >&2 "W: sync-dtb: ${dtbdir} NOT PRESENT"
fi
